<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="用户标识(数字0：未插入)" prop="userId">
        <el-input v-model="dataForm.userId" placeholder="用户标识(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="商品标识(数字0：未插入)" prop="goodId">
        <el-input v-model="dataForm.goodId" placeholder="商品标识(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="临时登陆的购物车，用户登陆后把购物车内容添加到该用户购物车下(字符串空：未插入)" prop="sessionId">
        <el-input v-model="dataForm.sessionId" placeholder="临时登陆的购物车，用户登陆后把购物车内容添加到该用户购物车下(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="商品的货号,取自表GOODS的GOODS_SN(字符串空：未插入)" prop="goodsSn">
        <el-input v-model="dataForm.goodsSn" placeholder="商品的货号,取自表GOODS的GOODS_SN(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="商品名称,取自表GOODS的GOODS_NAME(字符串空：未插入)" prop="goodsName">
        <el-input v-model="dataForm.goodsName" placeholder="商品名称,取自表GOODS的GOODS_NAME(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="市场价格,取自表市场价(数字0：未插入)" prop="marketPrice">
        <el-input v-model="dataForm.marketPrice" placeholder="市场价格,取自表市场价(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="商品的本店价,取自表GOODS的SHOP_PRICE(数字0：未插入)" prop="goodsPrice">
        <el-input v-model="dataForm.goodsPrice" placeholder="商品的本店价,取自表GOODS的SHOP_PRICE(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="商品的扩展属性, 取自GOODS的EXTENSION_CODE(数字0：未插入)" prop="goodsAttr">
        <el-input v-model="dataForm.goodsAttr" placeholder="商品的扩展属性, 取自GOODS的EXTENSION_CODE(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="取自ECS_GOODS的IS_REAL(数字0：未插入)" prop="isReal">
        <el-input v-model="dataForm.isReal" placeholder="取自ECS_GOODS的IS_REAL(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="商品的扩展属性,取自GOODS的EXTENSION_CODE(数字0：未插入)" prop="extensionCode">
        <el-input v-model="dataForm.extensionCode" placeholder="商品的扩展属性,取自GOODS的EXTENSION_CODE(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="该商品的父商品ID,没有该值为0,有的话那该商品就是该ID的配件(数字0：未插入)" prop="parentId">
        <el-input v-model="dataForm.parentId" placeholder="该商品的父商品ID,没有该值为0,有的话那该商品就是该ID的配件(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="购物车商品类型;0普通;1团够;2拍卖;3夺宝奇兵(数字0：未插入)" prop="recType">
        <el-input v-model="dataForm.recType" placeholder="购物车商品类型;0普通;1团够;2拍卖;3夺宝奇兵(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否赠品,0否;其他, 是参加优惠活动的ID,取值于FAVOURABLE_ACTIVITY的ACT_ID(数字0：未插入)" prop="isGift">
        <el-input v-model="dataForm.isGift" placeholder="是否赠品,0否;其他, 是参加优惠活动的ID,取值于FAVOURABLE_ACTIVITY的ACT_ID(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否邮寄(数字0：未插入)" prop="isShipping">
        <el-input v-model="dataForm.isShipping" placeholder="是否邮寄(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="能否处理（数字0：未插入)" prop="canHandsel">
        <el-input v-model="dataForm.canHandsel" placeholder="能否处理（数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="该商品的属性的ID,取自GOODS_ATTR的GOODS_ATTR_ID,如果有多个,只记录了最后一个,可能是BUG（数字0：未插入)" prop="goodsAttrId">
        <el-input v-model="dataForm.goodsAttrId" placeholder="该商品的属性的ID,取自GOODS_ATTR的GOODS_ATTR_ID,如果有多个,只记录了最后一个,可能是BUG（数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="该商品的购买数量255,实际库存不减少(数字0：未插入)" prop="goodAmount">
        <el-input v-model="dataForm.goodAmount" placeholder="该商品的购买数量255,实际库存不减少(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="操作员(字符串空：未插入)" prop="operator">
        <el-input v-model="dataForm.operator" placeholder="操作员(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="创建即上传时间(数字0：未插入)" prop="createUtc">
        <el-input v-model="dataForm.createUtc" placeholder="创建即上传时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="修改即更新时间(数字0：未插入)" prop="modifyUtc">
        <el-input v-model="dataForm.modifyUtc" placeholder="修改即更新时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否删除(数字0：未插入，1.未删除,2：删除，)" prop="isDeleted">
        <el-input v-model="dataForm.isDeleted" placeholder="是否删除(数字0：未插入，1.未删除,2：删除，)"></el-input>
      </el-form-item>
      <el-form-item label="版本号(数字0：未插入)" prop="version">
        <el-input v-model="dataForm.version" placeholder="版本号(数字0：未插入)"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import API from '@/api'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          userId: '',
          goodId: '',
          sessionId: '',
          goodsSn: '',
          goodsName: '',
          marketPrice: '',
          goodsPrice: '',
          goodsAttr: '',
          isReal: '',
          extensionCode: '',
          parentId: '',
          recType: '',
          isGift: '',
          isShipping: '',
          canHandsel: '',
          goodsAttrId: '',
          goodAmount: '',
          operator: '',
          createUtc: '',
          modifyUtc: '',
          isDeleted: '',
          version: ''
        },
        dataRule: {
          userId: [
            { required: true, message: '用户标识(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          goodId: [
            { required: true, message: '商品标识(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          sessionId: [
            { required: true, message: '临时登陆的购物车，用户登陆后把购物车内容添加到该用户购物车下(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          goodsSn: [
            { required: true, message: '商品的货号,取自表GOODS的GOODS_SN(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          goodsName: [
            { required: true, message: '商品名称,取自表GOODS的GOODS_NAME(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          marketPrice: [
            { required: true, message: '市场价格,取自表市场价(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          goodsPrice: [
            { required: true, message: '商品的本店价,取自表GOODS的SHOP_PRICE(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          goodsAttr: [
            { required: true, message: '商品的扩展属性, 取自GOODS的EXTENSION_CODE(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          isReal: [
            { required: true, message: '取自ECS_GOODS的IS_REAL(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          extensionCode: [
            { required: true, message: '商品的扩展属性,取自GOODS的EXTENSION_CODE(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          parentId: [
            { required: true, message: '该商品的父商品ID,没有该值为0,有的话那该商品就是该ID的配件(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          recType: [
            { required: true, message: '购物车商品类型;0普通;1团够;2拍卖;3夺宝奇兵(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          isGift: [
            { required: true, message: '是否赠品,0否;其他, 是参加优惠活动的ID,取值于FAVOURABLE_ACTIVITY的ACT_ID(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          isShipping: [
            { required: true, message: '是否邮寄(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          canHandsel: [
            { required: true, message: '能否处理（数字0：未插入)不能为空', trigger: 'blur' }
          ],
          goodsAttrId: [
            { required: true, message: '该商品的属性的ID,取自GOODS_ATTR的GOODS_ATTR_ID,如果有多个,只记录了最后一个,可能是BUG（数字0：未插入)不能为空', trigger: 'blur' }
          ],
          goodAmount: [
            { required: true, message: '该商品的购买数量255,实际库存不减少(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          operator: [
            { required: true, message: '操作员(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          createUtc: [
            { required: true, message: '创建即上传时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          modifyUtc: [
            { required: true, message: '修改即更新时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除(数字0：未插入，1.未删除,2：删除，)不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本号(数字0：未插入)不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            API.upkcart.info(this.dataForm.id).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.upkcart.userId
                this.dataForm.goodId = data.upkcart.goodId
                this.dataForm.sessionId = data.upkcart.sessionId
                this.dataForm.goodsSn = data.upkcart.goodsSn
                this.dataForm.goodsName = data.upkcart.goodsName
                this.dataForm.marketPrice = data.upkcart.marketPrice
                this.dataForm.goodsPrice = data.upkcart.goodsPrice
                this.dataForm.goodsAttr = data.upkcart.goodsAttr
                this.dataForm.isReal = data.upkcart.isReal
                this.dataForm.extensionCode = data.upkcart.extensionCode
                this.dataForm.parentId = data.upkcart.parentId
                this.dataForm.recType = data.upkcart.recType
                this.dataForm.isGift = data.upkcart.isGift
                this.dataForm.isShipping = data.upkcart.isShipping
                this.dataForm.canHandsel = data.upkcart.canHandsel
                this.dataForm.goodsAttrId = data.upkcart.goodsAttrId
                this.dataForm.goodAmount = data.upkcart.goodAmount
                this.dataForm.operator = data.upkcart.operator
                this.dataForm.createUtc = data.upkcart.createUtc
                this.dataForm.modifyUtc = data.upkcart.modifyUtc
                this.dataForm.isDeleted = data.upkcart.isDeleted
                this.dataForm.version = data.upkcart.version
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            var params = {
              'id': this.dataForm.id || undefined,
              'userId': this.dataForm.userId,
              'goodId': this.dataForm.goodId,
              'sessionId': this.dataForm.sessionId,
              'goodsSn': this.dataForm.goodsSn,
              'goodsName': this.dataForm.goodsName,
              'marketPrice': this.dataForm.marketPrice,
              'goodsPrice': this.dataForm.goodsPrice,
              'goodsAttr': this.dataForm.goodsAttr,
              'isReal': this.dataForm.isReal,
              'extensionCode': this.dataForm.extensionCode,
              'parentId': this.dataForm.parentId,
              'recType': this.dataForm.recType,
              'isGift': this.dataForm.isGift,
              'isShipping': this.dataForm.isShipping,
              'canHandsel': this.dataForm.canHandsel,
              'goodsAttrId': this.dataForm.goodsAttrId,
              'goodAmount': this.dataForm.goodAmount,
              'operator': this.dataForm.operator,
              'createUtc': this.dataForm.createUtc,
              'modifyUtc': this.dataForm.modifyUtc,
              'isDeleted': this.dataForm.isDeleted,
              'version': this.dataForm.version
            }
            var tick = !this.dataForm.id ? API.upkcart.add(params) : API.upkcart.update(params)
            tick.then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
